package model.solver;

import model.BasicResult;

/**
 * Represent the result of a solver execution. It provide some useful information as the status of
 * the execution or stdin and stderr.
 * 
 * @author GRONOWSKI Stephane svan001@aol.com
 * 
 *         igsat 2010
 * 
 */
public class SolverResult extends BasicResult {
	public static final String				DEFAULT_DESCRIPTION	= "Result of the solver";
	/** the default status of a solver execution */
	public static final SolverResultStatus	DEFAULT_STATUS		= SolverResultStatus.PROBLEM;
	/** the value use to know that the value is unknown */
	public static final int					UNKNOW_VALUE		= -1;

	private SolverResultStatus				status				= DEFAULT_STATUS;

	private int								restarts			= UNKNOW_VALUE;
	private int								conflics			= UNKNOW_VALUE;
	private int								decisions			= UNKNOW_VALUE;
	private int								propagations		= UNKNOW_VALUE;
	private int								conflicLiterals		= UNKNOW_VALUE;
	private String							solution			= null;

	/**
	 * Create a new solver result.
	 */
	public SolverResult() {
		description = DEFAULT_DESCRIPTION;
	}

	/**
	 * 
	 * @return the solution find by the solver or null.
	 */
	public String getSolution() {
		return solution;
	}

	/**
	 * Set the solution find by the solver.
	 * 
	 * @param solution
	 *            the solution.
	 */
	public void setSolution(String solution) {
		this.solution = solution;
	}

	@Override
	public String toString() {
		String res = description + " : \nStatus: " + status + "\n" + "Solving time: " + getPreprocTime() + "\nwith begin at : " + begin
				+ " ; end at :" + end + "\nMemory used : " + memoryUsed;

		res += "\nrestarts: " + restarts + "\nconflics: " + conflics + "\ndecisions: " + decisions + "\npropagations: " + propagations
				+ "\nconflict literals: " + conflicLiterals;

		if (solution != null)
			res += "\n Solution : " + solution;
		return res;
	}

	/**
	 * 
	 * @return the status of the execution {@link SolverResultStatus}.
	 */
	public SolverResultStatus getStatus() {
		return status;
	}

	/**
	 * Set the status of the execution {@link SolverResultStatus}.
	 * 
	 * @param status
	 *            the new status.
	 */
	public void setStatus(SolverResultStatus status) {
		this.status = status;
	}


	/**
	 * @deprecated
	 * @return the number of restart.
	 */
	public int getRestarts() {
		return restarts;
	}

	/**
	 * @deprecated Set the number of restart.
	 * 
	 * @param restarts
	 *            new number.
	 */
	public void setRestarts(int restarts) {
		this.restarts = restarts;
	}

	/**
	 * @deprecated
	 * @return the number of conflict.
	 */
	public int getConflics() {
		return conflics;
	}

	/**
	 * @deprecated Set the number of conflict.
	 * 
	 * @param conflics
	 *            the new value.
	 */
	public void setConflics(int conflics) {
		this.conflics = conflics;
	}

	/**
	 * @deprecated
	 * @return the number of decision.
	 */
	public int getDecisions() {
		return decisions;
	}

	/**
	 * @deprecated Set the number of decision.
	 * 
	 * @param decisions
	 *            new value.
	 */
	public void setDecisions(int decisions) {
		this.decisions = decisions;
	}

	/**
	 * @deprecated
	 * @return the number of propagation.
	 */
	public int getPropagations() {
		return propagations;
	}

	/**
	 * @deprecated Set the number of propagation.
	 * 
	 * @param propagations
	 *            the new value.
	 */
	public void setPropagations(int propagations) {
		this.propagations = propagations;
	}

	/**
	 * @deprecated
	 * 
	 * @return the number of conflict literals.
	 */
	public int getConflicLiterals() {
		return conflicLiterals;
	}

	/**
	 * @deprecated set the number of conflict literal.
	 * 
	 * @param conflicLiterals
	 *            new value.
	 */
	public void setConflicLiterals(int conflicLiterals) {
		this.conflicLiterals = conflicLiterals;
	}

}
